/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var stockholm = new google.maps.LatLng(59.32522, 18.07002);
var parliament = new google.maps.LatLng(59.327383, 18.06747);
var marker;
var map;
var geocoder;
function initializeGoogleMap() {
    geocoder = new google.maps.Geocoder();
    var mapOptions = {
        zoom: 13,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: stockholm
    };
        
        
        

    map = new google.maps.Map(document.getElementById('map_canvas'),
        mapOptions);

    marker = new google.maps.Marker({
        map:map,
        draggable:true,
        animation: google.maps.Animation.DROP,
        position: parliament
    //title: 'Que lugar es este?',
    //icon: 'http://google-maps-icons.googlecode.com/files/administration.png'
    });
    google.maps.event.addListener(marker, 'click', toggleBounce);
          
    google.maps.event.addListener(marker, 'dragend', dragEvent);
}
            
            
function dragEvent() {

    var latitud=document.getElementsByName("latitud");
    var longitud=document.getElementsByName("longitud");
    latitud[0].value=map.getCenter().lat();
    longitud[0].value=map.getCenter().lng();
    // myForm.validate();

}

function toggleBounce() {

    if (marker.getAnimation() != null) {
        marker.setAnimation(null);
    } else {
        marker.setAnimation(google.maps.Animation.BOUNCE);
    }
}





function codeAddress() {
                
    var address = document.getElementById('address').value;
    geocoder.geocode( {
        'address': address
    }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
                        
                        
            marker = new google.maps.Marker({
                map: map,
                draggable:true,
                animation: google.maps.Animation.DROP,
                position: results[0].geometry.location
            // title: 'Que lugar es este?',
            // icon: 'http://google-maps-icons.googlecode.com/files/administration.png'
            });
                        
                        
            google.maps.event.addListener(marker, 'click', toggleBounce);
            google.maps.event.addListener(marker, 'dragend', dragEvent);
          
                 
                        
                        
                        
        } else {
            alert('Geocode was not successful for the following reason: ' + status);
        }
    });
}
      
      
 
      
  
